package aes.client;

import javax.swing.text.*;

public class MaxLengthTextDocument extends PlainDocument {
	/**
	 * 
	 */
	private static final long serialVersionUID = 2827128066587492727L;
	//Store maximum characters permitted
	private int maxChars;
/**
 * Get max chars
 * @return
 */
	public int getMaxChars() {
		return maxChars;
	}
/**
 * Set Max Chars
 * @param maxChars
 */
	public void setMaxChars(int maxChars) {
		this.maxChars = maxChars;
	}

	@Override
	public void insertString(int offs, String str, AttributeSet a)
			throws BadLocationException {
		if(str != null && (getLength() + str.length() < maxChars)){
			super.insertString(offs, str, a);
		}
	}

	//getter e setter omitted
}